package kliment.display {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.printing.PrintJob;
	import flash.printing.PrintJobOptions;
	import kliment.utils.Transformation;
	
	/**
	 * 
	 * @author	Kliment
	 * @version	0.1.2
	 */
	public class Printer extends PrintJob {
		public function Printer() {
			super();
		}
		
		public function addPhotoPage(target:Sprite, crop:Boolean = false,  centred:Boolean = false):void {
			var xscale:Number = target.scaleX;
			var yscale:Number = target.scaleY;
			var x:Number = target.x;
			var y:Number = target.y;
			target.scaleX = 1;
			target.scaleY = 1;
			target.x = 0;
			target.y = 0;
			
			Transformation.to(target, Transformation.putInSpace(target, pageWidth, pageHeight, false, false));
			super.addPage(target, null, new PrintJobOptions(false));
			
			target.scaleX = xscale;
			target.scaleY = yscale;
			target.x = x;
			target.y = y;
		}
		
		public function addTransformPage(sprite:Sprite, transform:Matrix = null, printArea:Rectangle = null):void {
			var bitmapData:BitmapData = new BitmapData(pageWidth, pageHeight, true, 0x000000);
			bitmapData.draw(sprite, transform, null, null, null, true);
			var bitmap:Bitmap = new Bitmap(bitmapData);
			var printSource:Sprite = new Sprite();
			printSource.addChild(bitmap);
			super.addPage(printSource, printArea, new PrintJobOptions(false));
		}
		
	}
}